﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace V2 {
    public class SetUnion : IStreamingSet {
        private readonly List< IStreamingSet > m_Sets;
        private readonly List< ChangeHandler > m_Handlers;

        public SetUnion() {
            m_Handlers = new List< ChangeHandler >();
            m_Sets = new List< IStreamingSet >();
        }

        public SetUnion( IEnumerable< IStreamingSet > sets ) {
            m_Handlers = new List< ChangeHandler >();
            m_Sets = new List< IStreamingSet >( sets );
        }

        public void AddSet( IStreamingSet set ) {
            m_Sets.Add( set );
            foreach( ChangeHandler handler in m_Handlers ) {
                set.RowBinding += handler;
            }
        }

        public event ChangeHandler RowBinding {
            add {
                m_Handlers.Add( value );
                foreach( IStreamingSet t in m_Sets ) {
                    t.RowBinding += value;
                }
            }
            remove {
                m_Handlers.Remove( value );
                foreach( IStreamingSet t in m_Sets ) {
                    t.RowBinding -= value;
                }
            }
        }
    }
}